package com.atguigu.jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.Set;

public class Jedis_JedisPool {
    public static void main(String[] args) {
        //通过连接池获取连接

        //获取连接池的配置对象
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        //设置最大连接数
        jedisPoolConfig.setMaxTotal(100);

        //设置最大空闲连接数
        jedisPoolConfig.setMaxIdle(50);

        //1.获取连接池
        JedisPool jedisPool = new JedisPool(jedisPoolConfig,"hadoop102", 6379);

        //根据连接池获取连接对象
        Jedis jedis = null;

        try {
            jedis=jedisPool.getResource();
            Set<String> smembers = jedis.smembers("211027Set");
            for (String smember : smembers) {
                System.out.println(smember);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //释放连接
            //关闭连接
            if (jedis!=null){
                jedis.close();
            }
            //关闭连接池
            if (jedisPool!=null){
                jedisPool.close();
            }
        }




    }
}
